/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 *
 */

import { DistroFilterDimensionEnum } from '../enum/distro-filter-dimension-enum.js';
import { CoreModuleModelImpl } from '../model/module/core-module-model-impl.js';

import { DistroFilterConfig, DistroFilterHandler } from './distro-filter-handler.js';

/**
 * screenShape对象校验
 * policy:include/exclude
 * value:["rect","circle"]
 */
export class ScreenShapeHandler extends DistroFilterHandler {
  validateDistroFilterRequest(sourceDistroFilterConfig: DistroFilterConfig, targetDistroFilterConfig: DistroFilterConfig) {
    this.doRequest(sourceDistroFilterConfig, targetDistroFilterConfig, DistroFilterDimensionEnum.SCREEN_SHAPE);
  }

  getDimensionValue(distroFilterConfig: DistroFilterConfig): string[] | undefined {
    return this.getCommonDimensionValue(distroFilterConfig, ['circle', 'rect'], DistroFilterDimensionEnum.SCREEN_SHAPE, () => {
      const moduleModel = this.projectModel.getModuleModelByName(distroFilterConfig.moduleName) as CoreModuleModelImpl;
      this.logger
        ._buildError('Invalid screenShape value for distroFilter.')
        ._detail('Ensure that the value of screenShape for distroFilter is within the ["circle", "rect"] range.')
        ._file(DistroFilterHandler.getDetailFilePath(this.projectModel, moduleModel))
        ._printErrorAndExit();
    }) as string[] | undefined;
  }
}
